<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// 
//  login.php
//  www.6block.com
//  
//  Created by Will_Lee on 2011-05-19.
//  Copyright 2011 lishuzu. All rights reserved.
// 

class Login extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		$this->config->set_item('template', 'admin');
		$this->username = $this->config->item('adminuser');
		$this->password = $this->config->item('adminpwd');
		$this->md5_username = substr(md5($this->username), 0, 24);
		$this->md5_password = substr(md5($this->password), 0, 24);

	}
	
	function index(){
		$data = array();
		$username = $this->input->post('username') ? $this->input->post('username') : '';
		
		$password = $this->input->post('password') ? substr(md5($this->input->post('password')), 0, 24) : '';
		$loginsubmit = $this->input->post('loginsubmit') ? $this->input->post('loginsubmit') : '';
		if ($loginsubmit) {
			if (($username == $this->username) && ($password == $this->md5_password)) {
				$userinfo = array(
					'username' => $this->md5_username,
					'password' => $this->md5_password,
				);
				$this->session->set_userdata('adminuserinfo', $userinfo);
				showmessage('登录成功', 'admin/index', 3);
			}
		}
		$this->load->template('admin/login_tpl', $data);
	}
	function logout($username){
		if ($username == $this->md5_username) {
			$this->session->sess_destroy();
	          showmessage('退出成功', 'admin/login/index', 3);	
		}

	}
}
?>